package com.eshin.banner;

import java.io.PrintStream;

import org.springframework.boot.Banner;
import org.springframework.boot.SpringBootVersion;
import org.springframework.boot.ansi.AnsiColor;
import org.springframework.boot.ansi.AnsiOutput;
import org.springframework.boot.ansi.AnsiStyle;
import org.springframework.core.env.Environment;

public class MyBanner implements Banner {
	private static final String[] BANNER = { "",
			" ==========================================================",
			" ==    =====    =====   =     =    =====    =      =     ==", 
			" ==    =       =        =     =      =      ==     =     ==", 
			" ==    =       =        =     =      =      = =    =     ==", 
			" ==    =====   ======   = === =      =      =  =   =     ==", 
			" ==    =            =   =     =      =      =   =  =     ==", 
			" ==    =            =   =     =      =      =     ==     ==", 
			" ==    =====   =====    =     =    =====    =      =     ==", 
			" ==========================================================", 
			};

	private static final String SPRING_BOOT = " :: Spring Boot :: ";

	private static final int STRAP_LINE_SIZE = 42;
	@Override
	public void printBanner(Environment environment, Class<?> sourceClass, PrintStream out) {
		for (String line : BANNER) {
			out.println(line);
		}
		String version = SpringBootVersion.getVersion();
		version = (version == null ? "" : " (v" + version + ")");
		String padding = "";
		while (padding.length() < STRAP_LINE_SIZE
				- (version.length() + SPRING_BOOT.length())) {
			padding += " ";
		}

		out.println(AnsiOutput.toString(AnsiColor.GREEN, SPRING_BOOT,
				AnsiColor.DEFAULT, padding, AnsiStyle.FAINT, version));
		out.println();
	}

}
